package com.weixing.mall.provider.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.SysLog;
import com.weixing.mall.core.enums.OperateEnum;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.api.model.vo.AgentVo;
import com.weixing.mall.provider.model.enums.WhetherEnum;
import com.weixing.mall.provider.model.query.AgentQuery;
import com.weixing.mall.provider.service.IAgentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 代理商后台接口--管理后台使用
 *
 * @author siashan
 * @since v2.0.1
 */
@Validated
@RestController
@RequestMapping("agent")
public class AgentSysController extends BaseController {

    @Autowired
    private IAgentService agentService;


    /**
     * 加入黑名单
     *
     * @param agentId   代理商id
     * @return  加入结果
     */
    @PostMapping("black/pull/{agentId}")
    @SysLog(type = OperateEnum.U, desp = "代理商加入黑名单")
    public Result pullIntoBlack(@PathVariable Long agentId){
        return agentService.pullOrDetachBlack(agentId, WhetherEnum.YES.getValue());
    }

    /**
     * 移除黑名单
     *
     * @param agentId   代理商id
     * @return  移除结果
     */
    @PostMapping("black/detach/{agentId}")
    @SysLog(type = OperateEnum.U, desp = "代理商移除黑名单")
    public Result detachFromBlack(@PathVariable Long agentId){
        return agentService.pullOrDetachBlack(agentId,WhetherEnum.NO.getValue());
    }


    /**
     * 黑名单列表
     *
     * @param   query 查询条件
     * @return  黑名单列表
     */
    @GetMapping("black/list")
    @SysLog(type = OperateEnum.R, desp = "查询代理商黑名单")
    public Result<IPage<AgentVo>> blackList(AgentQuery query){
        query.setIsBlack(WhetherEnum.YES.getValue());
        IPage<AgentVo> page = agentService.selectListOfPage(initMpPage(), query, false);
        return ResultUtil.success(page);
    }

}
